<template>
  <div class="app-container">
    <part-comp title="活动规则" />
    <div class="whitebg boxradius mt_20" v-loading='loading'>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px"  class="demo-ruleForm">
            <el-form-item label="活动规则：" prop="msg">
                <editor v-model="ruleForm.msg" :min-height="200"/>
            </el-form-item>
            <el-form-item label="" prop="content">
                <el-button type="primary" class="savebtn" :loading='saveloading' @click="save">保  存</el-button>
            </el-form-item>
        </el-form>
    </div>
  </div>
</template>

<script>
import PartComp from '@/components/PartComp';
import { setTextDate,getTextData } from '@/api/activerule';
export default {
    components:{
        PartComp
    },
    data(){
        return {
            ruleForm:{
                msg:'',
            },
            rules:{
                msg:{ required: true, message: '请输入活动规则', trigger: 'blur' },
            },
            loading:false,
            saveloading:false
        }
    },

    created(){
        this.getData();
    },

    methods:{

        decodeHTM(html){
            var txt =document.createElement('textarea');
            txt.innerHTML = html;
            return txt.value;
        },

        getData(){
            this.loading=true;
           getTextData().then(res=>{
                // let data = res.data;
                this.ruleForm.msg = this.decodeHTM(res.data);
                // this.ruleForm.day = data.day;
                // this.ruleForm.time = data.time;
                // this.ruleForm.coin = data.coin;
                this.loading=false;
           })     
        },

        save(){
            this.$refs.ruleForm.validate(valid=>{
                if(!valid) return;
                this.saveloading = true;
                // let params = {...this.ruleForm};
                // params.time = Number(this.ruleForm.time)*60;
                setTextDate(this.ruleForm).then(res=>{
                    if(res.code == 1){
                        this.$message.success('设置成功');
                    }
                    this.getData();
                    this.saveloading = false;
                }).catch(e=>{
                    this.getData();
                    this.saveloading = false;
                })
            })
            
        }
    }
}
</script>

<style lang="scss" scoped>
.home_header{
    color: #000;
    font-size: 15px;
    font-weight: bold;
    margin: 15px 0;
}
.boxradius{
    border-radius: 6px;
    padding: 20px;
}
.lablefont{
    font-weight: 700;
    margin-bottom: 15px;
}
.line{
    margin: 0 15px;
    height: 36px;
    line-height: 36px;
}
.savebtn{
    width: 100px;
}
</style>